package com.ruoyi.project.loans.loansLog.controller;

import java.util.List;

import com.ruoyi.project.loans.loansLog.domain.LoansLog;
import com.ruoyi.project.loans.loansLog.service.ILoansLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 贷款记录信息操作处理
 * 
 * @author ruoyi
 * @date 2020-06-17
 */
@Controller
@RequestMapping("/loans/loansLog")
public class LoansLogController extends BaseController
{
    private String prefix = "/loans/loansLog";
	
	@Autowired
	private ILoansLogService loansLogService;
	
	@RequiresPermissions("loans:loansLog:view")
	@GetMapping()
	public String loansLog()
	{
	    return prefix + "/loansLog";
	}
	
	/**
	 * 查询贷款记录列表
	 */
	@RequiresPermissions("loans:loansLog:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(LoansLog loansLog)
	{
		startPage();
        List<LoansLog> list = loansLogService.selectLoansLogList(loansLog);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出贷款记录列表
	 */
	@RequiresPermissions("loans:loansLog:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LoansLog loansLog)
    {
    	List<LoansLog> list = loansLogService.selectLoansLogList(loansLog);
        ExcelUtil<LoansLog> util = new ExcelUtil<LoansLog>(LoansLog.class);
        return util.exportExcel(list, "loansLog");
    }
	
	/**
	 * 新增贷款记录
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存贷款记录
	 */
	@RequiresPermissions("loans:loansLog:add")
	@Log(title = "贷款记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(LoansLog loansLog)
	{		
		return toAjax(loansLogService.insertLoansLog(loansLog));
	}

	/**
	 * 修改贷款记录
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		LoansLog loansLog = loansLogService.selectLoansLogById(id);
		mmap.put("loansLog", loansLog);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存贷款记录
	 */
	@RequiresPermissions("loans:loansLog:edit")
	@Log(title = "贷款记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(LoansLog loansLog)
	{		
		return toAjax(loansLogService.updateLoansLog(loansLog));
	}
	
	/**
	 * 删除贷款记录
	 */
	@RequiresPermissions("loans:loansLog:remove")
	@Log(title = "贷款记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(loansLogService.deleteLoansLogByIds(ids));
	}

	/**
	 * 还款计划
	 */
	@GetMapping("/paymentDetail/{id}")
	public String paymentDetail(@PathVariable("id") Integer id, ModelMap mmap)
	{
		LoansLog loansLog = loansLogService.selectLoansLogById(id);
		mmap.put("loansLog", loansLog);
		return prefix + "/paymentDetail";
	}
	
}
